package com.gateway.pay.channel.strategy;


import com.gateway.pay.channel.dto.BaseRequest;
import com.gateway.pay.channel.dto.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.Objects;

/**
 *  策略上下文
 *  用于封装策略的对象，可以让策略互换
 */
@Slf4j
@Component
public class StrategyContext {
    private IThirdPartyStrategy strategy = null;

    /**
     * 实现了策略，可以通过此方法进行互换策略
     *
     * @param strategy
     */
    public void setStrategy(IThirdPartyStrategy strategy) {
        this.strategy = strategy;
    }

    /**
     * 执行具体的策略方法
     *
     * @param request
     * @return
     */
    public Result doRegister(BaseRequest request) {
        if ( this.strategy == null) {
            throw new RuntimeException("未配置此【 】策略");
        }
        return this.strategy.doRegister(request);
    }

}
